package com.car.sale.service;

import com.car.sale.entity.CarSale;
import com.car.sale.mapper.CarProductMapper;
import com.car.sale.mapper.CarSaleMapper;
import com.car.sale.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@Service
public class CarService {
    @Autowired
    private CarProductMapper carProductMapper;
    @Autowired
    private CarSaleMapper carSaleMapper;

    List<String> carSize;

    public List<Top> getCarTop() {
        List<Top> carTop = new ArrayList<>();
        carSize = carProductMapper.getCarType();
        String type;
        Query query = new Query();
        query.setType("轿车");
//        从数据库获取所有类型的车（大型中型小型，依次查询对照的销量
        for(int i=0;i<carSize.size();i++)
        {
            type = (String)carSize.get(i);
            Top top = new Top();
            top.setName(type);
            query.setSize(top.getName());
            top.setCar(carSaleMapper.getCarTop(query));
            System.out.println(type+top.getCar().size());
            carTop.add(top);
        }
        return carTop;
    }
//      数量占比，返回{大型；250}
//    国产热门车，返回{gle，200}
    public List<Count> getCarCount() {
        return carSaleMapper.getCountByType("轿车");

    }
//      数量占比，返回{大型；每个月}
//    国产热门车，返回{gle，每个月}
    public List<Month> getCarMonth() {
        carSize = carProductMapper.getCarType();
        List<Month> monthList = new ArrayList<>();
        Query query = new Query();
        query.setType("轿车");
        for (int i = 0; i < carSize.size(); i++)
        {
            Month month = new Month();
            month.setType(carSize.get(i));
            query.setSize(month.getType());
            month.setMonth(carSaleMapper.getMonthByType(query));
            monthList.add(month);
        }
        return monthList;
    }
}
